import { BaseEntity } from '../../../shared/baseEntity';
import { SimJobType, SimulationResult } from '../type/index';
import { SimJobStatus, SimulationSpec } from '../type';
import { Unique, Entity, Column, PrimaryGeneratedColumn } from 'typeorm';

@Entity('simulation_jobs')
export class SimulationJob extends BaseEntity {

  @PrimaryGeneratedColumn()
  public id: number;

  @Column()
  public product: string;

  @Column({ nullable: true })
  public desc: string;

  @Column({ nullable: true })
  public business_id: string;

  @Column({
    type: 'enum',
    enum: SimJobStatus
  })
  public status: SimJobStatus;

  @Column({ nullable: true })
  public agent_id: string; // agent identity

  @Column({ nullable: true })
  public user_id: string;
  
  @Column({ nullable: true })
  public app_id: string;

  @Column({ nullable: true })
  public node_id: string;

  @Column({ nullable: true })
  public debug: boolean;

  @Column({ nullable: true })
  public notification_callback: string;

  @Column('json')
  public spec: SimulationSpec;

  @Column({
    type: 'json',
    nullable: true
  })
  public result: SimulationResult;

  @Column({ nullable: true })
  public message: string;

  @Column({
    type: 'timestamptz'
  })
  public submit_at: Date;

  /**
   * https://stackoverflow.com/questions/62696628/how-can-i-create-columns-with-type-date-and-type-datetime-in-nestjs-with-typeorm
   */
  @Column({
    nullable: true,
    type: 'timestamptz'
  })
  public started_at: Date;
  
  @Column({
    nullable: true,
    type: 'timestamptz'
  })
  public finished_at: Date;

  @Column({
    nullable: true
  })
  public progress: number;

  @Column({
    nullable: true
  })
  public type: string;

  @Column('int', {
    nullable: true,
    array: true
  })
  public subJobIds: number[];

  @Column({
    nullable: true
  })
  public parentJobId: number;

}